package org.ucas.faker.web.fetcher.meta;

import java.io.Serializable;

public class ColumnField  implements Serializable {

  public Table table;

  public String column;

  public String alias; // 在类中对应的属性名

  public Class jdbcType;

  public static ColumnField ANY = new ColumnField();

  static {
    ANY.column = "*";
  }

  public ColumnField() {
  }

  public ColumnField(String column) {
    this.column = column;
  }

  public ColumnField(Table table, String column) {
    this.table = table;
    this.column = column;
  }

  public void replace(Table src, Table dst) {
    if(table != null && table.equals(src)) table = dst;
  }

  public String sql() {
    return table == null? column : table.name + "." + column;
  }

  @Override
  public int hashCode() {
    return sql().hashCode();
  }
}
